package com.my;

import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
import java.util.Properties;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;
import java.util.regex.Matcher;   
import java.util.regex.Pattern;
public class test1 {
	private Properties props; 
	public static void main(String[] args){
//		String input="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;root&gt;&lt;Status&gt;1&lt;/Status&gt;&lt;ErrCode&gt;&lt;/ErrCode&gt;&lt;ReportInfo&gt;&lt;SMSMobileCount&gt;1&lt;/SMSMobileCount&gt;&lt;SMSContentCount&gt;1&lt;/SMSContentCount&gt;&lt;SMSSendCount&gt;1&lt;/SMSSendCount&gt;&lt;ReportDespr&gt;&#x672C;&#x6B21;&#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x624B;&#x673A;&#x53F7;&#x5171;&#x8BA1;1&#x4E2A;&#xFF0C;&#x77ED;&#x4FE1;&#x5185;&#x5BB9;&#x62C6;&#x5206;&#x4E3A;1&#x6761;&#xFF0C;&#x6263;&#x8D39;1&#x70B9;&lt;/ReportDespr&gt;&lt;/ReportInfo&gt;&lt;/root&gt;";
//      input=input.replaceAll("&amp;","&"); 
//      input=input.replaceAll("&apos;","'"); 
//      input=input.replaceAll("&quot;","\""); 
//      input=input.replaceAll("&lt;","<"); 
//      input=input.replaceAll("&gt;",">"); 
//      input=input.replaceAll("&nbsp;"," "); 
//      input=input.replaceAll("<br>","\r\n"); 
//      input=input.replaceAll("<br>","\r"); 
//      input=input.replaceAll(" <br>","\n"); 
//		System.out.println(input);
//		ReadConfigXml(input);

//		String a="<?xml version='1.0' encoding='utf-8'?><root><Status>1</Status><ErrCode></ErrCode><ReportInfo><SMSMobileCount>1</SMSMobileCount><SMSContentCount>1</SMSContentCount><SMSSendCount>1</SMSSendCount><ReportDespr>&#x672C;&#x6B21;&#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x624B;&#x673A;&#x53F7;&#x5171;&#x8BA1;1&#x4E2A;&#xFF0C;&#x77ED;&#x4FE1;&#x5185;&#x5BB9;&#x62C6;&#x5206;&#x4E3A;1&#x6761;&#xFF0C;&#x6263;&#x8D39;1&#x70B9;</ReportDespr></ReportInfo></root>";
//		System.out.println(UnicodeToString(a));
		
		test();
	}
	
	public static void test(){
		String a="<?xml version='1.0' encoding='utf-8'?><root><Status>1</Status><ErrCode></ErrCode><ReportInfo><SMSMobileCount>1</SMSMobileCount><SMSContentCount>1</SMSContentCount><SMSSendCount>1</SMSSendCount><ReportDespr>&#x672C;&#x6B21;&#x53D1;&#x9001;&#x77ED;&#x4FE1;&#x624B;&#x673A;&#x53F7;&#x5171;&#x8BA1;1&#x4E2A;&#xFF0C;&#x77ED;&#x4FE1;&#x5185;&#x5BB9;&#x62C6;&#x5206;&#x4E3A;1&#x6761;&#xFF0C;&#x6263;&#x8D39;1&#x70B9;</ReportDespr></ReportInfo></root>";
		try {
			System.out.println(URLDecoder.decode(a,"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
    public static String UnicodeToString(String str) {
        Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");    
        Matcher matcher = pattern.matcher(str);
        char ch;
        while (matcher.find()) {
            ch = (char) Integer.parseInt(matcher.group(2), 16);
            str = str.replace(matcher.group(1), ch + "");    
        }
        return str;
    }
	public static void ReadConfigXml(String url){
        StringReader read = new StringReader(url);  
        //创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入  
        InputSource source = new InputSource(read);  
        //创建一个新的SAXBuilder  
        SAXBuilder sb = new SAXBuilder();  
        try {  
            //通过输入源构造一个Document  
            Document doc = sb.build(source);  
            //取的根元素  
            Element root = doc.getRootElement();  
//            System.out.println(root.getName()+":"+root.getValue());  
              
            List child = root.getChildren();  
            Element e = null;  
            e = (Element)child.get(0);
            System.out.println(e.getName()+":"+e.getValue()); 
            e = (Element)child.get(1);
            System.out.println(e.getName()+":"+e.getValue()); 
//            for (int i = 0; i < child.size(); i++){  
//                e = (Element)child.get(i); 
//                System.out.println(e.getName()+":"+e.getValue());  
//            }  
        }catch(JDOMException e){  
            e.printStackTrace();  
        }catch(IOException ioe){  
            ioe.printStackTrace();  
        }  
	}
	
	 public static String replaceInString(String in, String from, String to) {

		 StringBuffer sb = new StringBuffer(in.length() * 2);

		 String posString = in.toLowerCase();

		 String cmpString = from.toLowerCase();

		 int i = 0;

		 boolean done = false;

		 while (i < in.length() && !done) {

		  int start = posString.indexOf(cmpString, i);

		  if (start == -1) {

		 done = true;

		 } else {

		 sb.append(in.substring(i, start) + to);

		  i = start + from.length();

		 }

		 }

		  if (i < in.length()) {

		  sb.append(in.substring(i));

		 }

		 return sb.toString();

		 }
//    public   static   String   HtmlReverse(String   strInput)   { 
//        String   input   =   strInput; 
//              if   ( " ".equals(input)   ||   input==null)   { 
//                return   " "; 
//        }   else   { 
//                input=replace(input,"&amp;","&"); 
//                input=Replace(input,"&apos;","'"); 
//                input=Replace(input,"&quot;","\""); 
//                input=Replace(input,"&lt;","<"); 
//                input=Replace(input,"&gt;",">"); 
//                input=Replace(input,"&nbsp;"," "); 
//                input=Replace(input,"<br>","\r\n"); 
//                input=Replace(input,"<br>","\r"); 
//                input=Replace(input," <br>","\n"); 
//                return   input; 
//        } 
//}
}
